import 'widget/radio_item.dart';
import 'package:bruno/bruno.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../base/get/get_common_view.dart';
import 'package:get/get.dart';
import '../../res/colors.dart';
import '../../res/r.dart';
import '../../res/strings.dart';
import '../../res/style.dart';
import '../../util/keyboard_util.dart';
import '../../widget/_toolbar.dart';
import '../../../http/request_api.dart';
import '../../../res/button_style.dart';
import '../../../res/global_user_info.dart';
import '../../../util/web_util.dart';
import 'login_controller.dart';
import 'package:flutter/material.dart';

import 'widget/edit_widget.dart';

class LoginPage extends GetCommonView<LoginController> {
  const LoginPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 0.0,
        centerTitle: true,
        leading: GestureDetector(
          onTap: Get.back,
          child: const Icon(
            Icons.arrow_back_ios,
            color: Colors.white,
          ),
        ),
        title: Text(
          '登录',
          style: Styles.style_white_16,
        ),
        backgroundColor: const Color(0xFFEA000B),
      ),
      resizeToAvoidBottomInset: false,
      body: Stack(
        children: [
          Image.asset(
            R.bg,
            width: 390.w,
            height: 180.h,
            fit: BoxFit.fill,
          ),
          Padding(
            padding: const EdgeInsets.only(left: 15, right: 15, top: 30).r,
            child: SizedBox(
              height: 430.h,
              child: BrnShadowCard(
                padding: const EdgeInsets.all(7).r,
                color: Colors.white,
                circular: 10,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Padding(
                      padding: const EdgeInsets.only(left: 15, top: 20).r,
                      child: Text(
                        "手机快捷登录",
                        style: Styles.style_black_16_w700,
                      ),
                    ),

                    Box.vBox20,

                    ///账户名输入框
                    EditWidget(
                      imgName: R.phone,
                      hintText: '请输入手机号',
                      textInputType: TextInputType.number,
                      onChanged: (text) => controller
                        ..account = text
                        ..update(),
                    ),
                    DividerStyle.divider1HalfPadding26,

                    EditWidget(
                      codeType: true,
                      imgName: R.checkcode,
                      hintText: '请输入验证码',
                      textInputType: TextInputType.number,
                      onChanged: (text) => controller
                        ..checkCode = text
                        ..update(),
                    ),
                    DividerStyle.divider1HalfPadding26,

                    Box.vBox20,

                    Padding(
                      padding: const EdgeInsets.only(left: 15, right: 15).r,
                      child: Text.rich(TextSpan(
                          style: const TextStyle(height: 1.5),
                          children: [
                            WidgetSpan(child: RadioItem(
                              onchange: (value) {
                                controller.isAgree = value;
                                controller.update();
                              },
                            )),
                            // TextSpan(text: " "),
                            TextSpan(
                                text: '  我已阅读并同意',
                                style: Styles.style_black_14),
                            WidgetSpan(
                                child: GestureDetector(
                              onTap: () {
                                // WebUtil.toWebPage(
                                //     title: "用户服务协议",
                                //     link: RequestApi.rule_html,
                                //     id: 0);
                              },
                              child: Text(
                                "《用户服务协议》",
                                style: Styles.style_red_13,
                              ),
                            )),
                            TextSpan(text: '及', style: Styles.style_black_13),
                            WidgetSpan(
                                child: GestureDetector(
                              onTap: () {
                                WebUtil.toWebPage(
                                    title: "隐私政策", link: "", id: 0);
                              },
                              child: Text(
                                "《隐私政策》",
                                style: Styles.style_red_13,
                              ),
                            )),
                            TextSpan(text: '和', style: Styles.style_black_13),
                            WidgetSpan(
                                child: GestureDetector(
                              onTap: () {
                                WebUtil.toWebPage(
                                    title: "第三方信息共享清单", link: "", id: 0);
                              },
                              child: Text(
                                "《第三方信息共享清单》",
                                style: Styles.style_red_13,
                              ),
                            )),
                          ])),
                    ),

                    Box.vBox20,

                    ///登录按钮
                    Container(
                      width: double.infinity,
                      height: 50.h,
                      margin: const EdgeInsets.only(left: 25, right: 25).r,
                      decoration: const BoxDecoration(
                        color: ColorStyle.color_backgroud4,
                        borderRadius: BorderRadius.all(Radius.circular(30)),
                        boxShadow: [
                          BoxShadow(
                            color: ColorStyle.color_home,
                            offset: Offset(0, 0),
                            blurRadius: 1,
                            spreadRadius: 0,
                          ),
                        ],
                      ),
                      child: TextButton(
                          style: controller.changeShowButton()
                              ? ButtonStyles.getButtonStyle()
                              : ButtonStyles.getTransparentStyle(),
                          onPressed: () {
                            KeyboardUtils.hideKeyboard(context);
                            controller.login();
                          },
                          child: Text(
                            "立即登录",
                            style: controller.changeShowButton()
                                ? Styles.style_white_16
                                : Styles.style_white38_16,
                          )),
                    ),
                  ],
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
